<!-- HTML header for doxygen 1.8.13-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>MTB CAT1 Peripheral driver library: CAN FD       (CAN with Flexible Data-Rate)</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen_style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><a href="http://www.cypress.com/"><img alt="Logo" src="IFXCYP_one-line.png"/></a></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">MTB CAT1 Peripheral driver library</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('group__group__canfd.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="summary">
<a href="#groups">API Reference</a>  </div>
  <div class="headertitle">
<div class="title">CAN FD (CAN with Flexible Data-Rate)</div>  </div>
</div><!--header-->
<div class="contents">
<a name="details" id="details"></a><h2 class="groupheader">General Description</h2>
<p>The CAN FD driver provides an easy method to access the CAN FD IP block registers and provides simple functionality for sending and receiving data between devices in the CAN FD network. </p>
<p>The CAN FD driver provides an API to configure the main features - mode, bit time, message buffers - and transmit and receive message in all modes:</p><ul>
<li>Classic CAN using 11-bit identifiers</li>
<li>Classic CAN using 29-bit identifiers</li>
<li>CAN Flexible Data using 11-bit identifiers</li>
<li>CAN Flexible Data using 29-bit identifiers.</li>
</ul>
<div class="image">
<img src="canfd_solution.png" alt="canfd_solution.png" width="948px"/>
<div class="caption">
CAN FD Solution</div></div>
 <h1><a class="anchor" id="group_canfd_section_configuration"></a>
Configuration Considerations</h1>
<p>Specification of the sample code is as follows:</p><ul>
<li>Selectable CAN FD mode or CAN mode</li>
<li>Configurable CAN clock</li>
<li>Configurable CAN Bit rate</li>
<li>Configurable CAN FD Bit rate</li>
<li>Configurable Standard ID filter</li>
<li>Configurable Extended Message ID Filter</li>
<li>Tx-Rx Element Size : 8 bytes (CAN mode)</li>
<li>Tx-Rx Element Size : 64 bytes (CAN FD mode)</li>
<li>Rx FIFO configuration</li>
<li>Interrupts : <br />
 CY_CANFD_RX_FIFO_0_NEW_MESSAGE (Message stored to Rx FIFO 0) <br />
 CY_CANFD_RX_FIFO_1_NEW_MESSAGE (Message stored to Rx FIFO 1) <br />
 CY_CANFD_RX_BUFFER_NEW_MESSAGE (Message stored to Dedicated Rx Buffer). <br />
 Sends data of ID:0x200 periodically in the main(). Echobacks received data by incrementing the ID of the received packet in the receiving interrupt.(CanFDIrqHandler() &mdash; CanFDCallbackRx())</li>
</ul>
<h2><a class="anchor" id="group_canfd_section_configuration_personalities"></a>
Use ModusToolbox Device Configurator Tool to generate initialization code</h2>
<p>The steps to generate initialization code using the ModusToolbox Device Configurator Tool:</p>
<ol type="1">
<li>Launch the ModusToolbox Device Configurator Tool.</li>
<li>Switch to the Peripherals tab. Enable the CAN FD channel personality under Communication and enter Alias (default is canfd_0_chan_0).</li>
<li>Go to the Parameters Pane for the CAN FD Personality and configure it with the desired parameters (set the Clock Signal divider, set the bit timing configuration, set the other parameters per Configuration Considerations, etc).</li>
<li>Perform File-&gt;Save for the initialization code to generate.</li>
</ol>
<p>Now, all required CAN FD initialization code and configuration prerequisites will be generated:</p>
<ul>
<li>The Peripheral Clock Divider assignment and analog routing are parts of the init_cycfg_all() routine. Place the call of the init_cycfg_all() function before using any CAN FD API functions to ensure initialization of all external resources required for the CAN FD operation.</li>
<li>The CAN FD configuration structure declaration is in the cycfg_peripherals.h file and its initialization is in the cycfg_peripherals.c file. The variable name is &lt;CAN_FD_Alias_Name&gt;_config (default is canfd_0_chan_0_config). It must be used with <a class="el" href="group__group__canfd__functions.html#ga8a1f6cffafdd899861203d50d24e7b3e" title="Initializes the CAN FD module. ">Cy_CANFD_Init()</a> function.</li>
<li>TX buffers structures are initialized. Use these structures to send data.</li>
</ul>
<p>For the CAN FD interrupt service routine, <a class="el" href="group__group__canfd__functions.html#ga89c366a3feb3ef1cd0a3b9779fff718e" title="CAN FD (Status/Error/Rx/Tx) interrupt ISR. ">Cy_CANFD_IrqHandler()</a> can be used. It handles reading data from the dedicated RX buffers and RX FIFO buffers. Corresponding callback functions are called for error interrupts, RX interrupts and TX complete interrupt. Put the names of callback functions to the Callback functions parameters section. Put NULL if no callback function to be used. </p><dl class="section note"><dt>Note</dt><dd>Only RX interrupt sources are enabled by default. Use <a class="el" href="group__group__canfd__functions.html#ga054d85e42f3f2440743c981dbc52ed0a" title="Configures which bits of the interrupt request register can trigger an interrupt event. ">Cy_CANFD_SetInterruptMask()</a> to enable other interrupt sources. </dd>
<dd>
Interrupt flags are set regardless of the interrupt enable register. Cy_CANFD_IrqHandler will check and process all supported interrupts when triggered with any enabled interrupt source.</dd></dl>
<div class="fragment"><div class="line"><span class="comment">/* CANFD interrupt handler */</span></div><div class="line"><span class="keywordtype">void</span> CanfdInterruptHandler(<span class="keywordtype">void</span>)</div><div class="line">{</div><div class="line">    <span class="comment">/* Just call the IRQ handler with the current channel number and context */</span></div><div class="line">    <a class="code" href="group__group__canfd__functions.html#ga89c366a3feb3ef1cd0a3b9779fff718e">Cy_CANFD_IrqHandler</a>(CANFD0, 0, &amp;context);</div><div class="line">}</div></div><!-- fragment --><p> Set up the interrupt handler to be called with CAN FD events. The CAN FD block has two interrupt lines which can be assigned to different interrupt sources using <a class="el" href="group__group__canfd__functions.html#ga4f70384d4189cb8a2c95558844b3ad32" title="Configures the bits of the Interrupt Line Select Register to assign the interrupt signal to the line ...">Cy_CANFD_SetInterruptLine()</a>: canfd_0_interrupts0_0_IRQn and canfd_0_interrupts1_0_IRQn. Also, the CAN FD block has a consolidated interrupt canfd_0_interrupt0_IRQn. The following code shows how to set up the interrupt handler. </p><div class="fragment"><div class="line">    <span class="comment">/* Setup the CANFD interrupt */</span></div><div class="line">    {</div><div class="line">        <span class="comment">/* Populate the configuration structure */</span></div><div class="line">        <span class="keyword">const</span> <a class="code" href="structcy__stc__sysint__t.html">cy_stc_sysint_t</a> irq_cfg =</div><div class="line">        {</div><div class="line">            <span class="comment">/* .intrSrc */</span> canfd_0_interrupts0_0_IRQn, <span class="comment">/* CAN FD interrupt number */</span></div><div class="line">            <span class="comment">/* .intrPriority */</span> 3UL</div><div class="line">        };</div><div class="line"></div><div class="line">        <span class="comment">/* Hook the interrupt service routine and enable the interrupt */</span></div><div class="line">        (void) <a class="code" href="group__group__sysint__functions.html#gab2ff6820a898e9af3f780000054eea5d">Cy_SysInt_Init</a>(&amp;irq_cfg, &amp;CanfdInterruptHandler);</div><div class="line">        NVIC_EnableIRQ(canfd_0_interrupts0_0_IRQn);</div><div class="line">    }</div></div><!-- fragment --> <h2><a class="anchor" id="group_canfd_section_configuration_manual"></a>
Implement the initialization code manually</h2>
<p>Call <a class="el" href="group__group__canfd__functions.html#ga8a1f6cffafdd899861203d50d24e7b3e" title="Initializes the CAN FD module. ">Cy_CANFD_Init()</a> to initialize the CAN FD module. It initializes the CAN FD module with the configuration parameters, passed in the <a class="el" href="structcy__stc__canfd__config__t.html">cy_stc_canfd_config_t</a> structure. It consists of several elements to be defined first. </p><div class="fragment"><div class="line">    <span class="keyword">const</span> <a class="code" href="structcy__stc__canfd__config__t.html">cy_stc_canfd_config_t</a> config =</div><div class="line">    {</div><div class="line">        <span class="comment">/* .txCallback            */</span> NULL,</div><div class="line">        <span class="comment">/* .rxCallback            */</span> CAN_RxMsgCallback,</div><div class="line">        <span class="comment">/* .errorCallback         */</span> NULL,</div><div class="line">        <span class="comment">/* .canFDMode             */</span> <span class="keyword">true</span>,</div><div class="line">        <span class="comment">/* .bitrate               */</span> &amp;bitrateConfig,</div><div class="line">        <span class="comment">/* .fastBitrate           */</span> &amp;fastBitrateConfig,</div><div class="line">        <span class="comment">/* .tdcConfig             */</span> &amp;tdcConfig,</div><div class="line">        <span class="comment">/* .sidFilterConfig       */</span> &amp;sidFiltersConfig,</div><div class="line">        <span class="comment">/* .extidFilterConfig     */</span> &amp;extidFiltersConfig,</div><div class="line">        <span class="comment">/* .globalFilterConfig    */</span> &amp;globalFilterConfig,</div><div class="line">        <span class="comment">/* .rxBufferDataSize      */</span> <a class="code" href="group__group__canfd__enums.html#gga597fe2f69a8484277fd481ac5384ca7ca2a6fe8e5944a3c017b15cce584d421ee">CY_CANFD_BUFFER_DATA_SIZE_64</a>,</div><div class="line">        <span class="comment">/* .rxFIFO1DataSize       */</span> <a class="code" href="group__group__canfd__enums.html#gga597fe2f69a8484277fd481ac5384ca7ca2a6fe8e5944a3c017b15cce584d421ee">CY_CANFD_BUFFER_DATA_SIZE_64</a>,</div><div class="line">        <span class="comment">/* .rxFIFO0DataSize       */</span> <a class="code" href="group__group__canfd__enums.html#gga597fe2f69a8484277fd481ac5384ca7ca2a6fe8e5944a3c017b15cce584d421ee">CY_CANFD_BUFFER_DATA_SIZE_64</a>,</div><div class="line">        <span class="comment">/* .txBufferDataSize      */</span> <a class="code" href="group__group__canfd__enums.html#gga597fe2f69a8484277fd481ac5384ca7ca2a6fe8e5944a3c017b15cce584d421ee">CY_CANFD_BUFFER_DATA_SIZE_64</a>,</div><div class="line">        <span class="comment">/* .rxFIFO0Config         */</span> &amp;rxFifo0Config,</div><div class="line">        <span class="comment">/* .rxFIFO1Config         */</span> &amp;rxFifo1Config,</div><div class="line">        <span class="comment">/* .noOfRxBuffers         */</span> 0x4u,</div><div class="line">        <span class="comment">/* .noOfTxBuffers         */</span> 0x2u,</div><div class="line">        <span class="comment">/* .messageRAMaddress     */</span> CY_CAN0MRAM_BASE,</div><div class="line">        <span class="comment">/* .messageRAMsize        */</span> 4096u</div><div class="line">    };</div></div><!-- fragment --><p>The <a class="el" href="group__group__canfd__functions.html#ga8a1f6cffafdd899861203d50d24e7b3e" title="Initializes the CAN FD module. ">Cy_CANFD_Init()</a> function also initializes the shared context structure used later with other API functions. </p><div class="fragment"><div class="line"><a class="code" href="structcy__stc__canfd__context__t.html">cy_stc_canfd_context_t</a> context = {0}; <span class="comment">/* This is a shared context structure, </span></div><div class="line"><span class="comment">                                 * unique for each channel </span></div><div class="line"><span class="comment">                                 */</span></div></div><!-- fragment --><p>Although the callback functions are optional, they are recommended for use, otherwise, there is no report to the API about any error and transmission or reception events. The example callback function sends received data back to the bus, incrementing ID by 1: </p><div class="fragment"><div class="line"><span class="comment">/* CANFD reception callback */</span></div><div class="line"><span class="keywordtype">void</span> CAN_RxMsgCallback(<span class="keywordtype">bool</span> bRxFifoMsg, uint8_t u8MsgBufOrRxFifoNum, </div><div class="line">                       <a class="code" href="structcy__stc__canfd__rx__buffer__t.html">cy_stc_canfd_rx_buffer_t</a>* pstcCanFDmsg)</div><div class="line">{</div><div class="line">    <span class="keywordflow">if</span>(0 == pstcCanFDmsg-&gt;<a class="code" href="structcy__stc__canfd__rx__buffer__t.html#a602b97b15de68d54ccb557ed4c501e20">r0_f</a>-&gt;<a class="code" href="structcy__stc__canfd__r0__t.html#a80c311872aedfda473862d01643682e6">rtr</a>) <span class="comment">/* Only for data frames */</span></div><div class="line">    {</div><div class="line">        <span class="comment">/* Sets up the CANFD TX Buffer for response */</span></div><div class="line">            <a class="code" href="structcy__stc__canfd__t0__t.html">cy_stc_canfd_t0_t</a> t0registerMsg0 =</div><div class="line">            {</div><div class="line">                <span class="comment">/* id   */</span>  pstcCanFDmsg-&gt;<a class="code" href="structcy__stc__canfd__rx__buffer__t.html#a602b97b15de68d54ccb557ed4c501e20">r0_f</a>-&gt;<a class="code" href="structcy__stc__canfd__r0__t.html#a82b8a4316d88b483958958bc6eccda38">id</a> + 1, <span class="comment">/* Message ID is incremented*/</span></div><div class="line">                <span class="comment">/* rtr   */</span> <a class="code" href="group__group__canfd__enums.html#gga9dc2150b5a115fd87cd60f538f7281ceac797e947012ac4b5d191f67b5095682c">CY_CANFD_RTR_DATA_FRAME</a>,</div><div class="line">                <span class="comment">/* xtd   */</span> pstcCanFDmsg-&gt;<a class="code" href="structcy__stc__canfd__rx__buffer__t.html#a602b97b15de68d54ccb557ed4c501e20">r0_f</a>-&gt;<a class="code" href="structcy__stc__canfd__r0__t.html#ad82c419283c2f7f4f2ed1e8eafe50292">xtd</a>,</div><div class="line">                <span class="comment">/* esi */</span> <a class="code" href="group__group__canfd__enums.html#gga24bb5c7075c10594b4e276520f64f779a46390b4ec4de5f7c1819fe9f1a0ebbec">CY_CANFD_ESI_ERROR_ACTIVE</a></div><div class="line">            };</div><div class="line"></div><div class="line">            <a class="code" href="structcy__stc__canfd__t1__t.html">cy_stc_canfd_t1_t</a> t1registerMsg0 =</div><div class="line">            {</div><div class="line">                <span class="comment">/* dlc   */</span> pstcCanFDmsg-&gt;<a class="code" href="structcy__stc__canfd__rx__buffer__t.html#ac4fdc02124190194f9093018dfffbc3e">r1_f</a>-&gt;<a class="code" href="structcy__stc__canfd__r1__t.html#ad2c446d9edb17be86dcb8c20606473a9">dlc</a>,</div><div class="line">                <span class="comment">/* brs   */</span> <span class="keyword">true</span>,</div><div class="line">                <span class="comment">/* fdf   */</span> (<span class="keyword">true</span>) ? <a class="code" href="group__group__canfd__enums.html#gga9a9a243726110708a6e61d77b7a86d1ea0053337533518903d9fa1ec0729a22d2">CY_CANFD_FDF_CAN_FD_FRAME</a> : <a class="code" href="group__group__canfd__enums.html#gga9a9a243726110708a6e61d77b7a86d1ea16e079ea2b407c5c68f8dfd9f3075553">CY_CANFD_FDF_STANDARD_FRAME</a>,</div><div class="line">                <span class="comment">/* efc   */</span> <span class="keyword">false</span>,</div><div class="line">                <span class="comment">/* mm    */</span> 0UL</div><div class="line">            };</div><div class="line"></div><div class="line">            <a class="code" href="structcy__stc__canfd__tx__buffer__t.html">cy_stc_canfd_tx_buffer_t</a> txBuffer =</div><div class="line">            {</div><div class="line">                <span class="comment">/* t0_f        */</span> &amp;t0registerMsg0,</div><div class="line">                <span class="comment">/* t1_f        */</span> &amp;t1registerMsg0,</div><div class="line">                <span class="comment">/* data_area_f */</span> pstcCanFDmsg-&gt;<a class="code" href="structcy__stc__canfd__rx__buffer__t.html#a0db6cdd9b30082a0639b997703f2aec1">data_area_f</a></div><div class="line">            };</div><div class="line">        <span class="comment">/* Sends the same message back with an incremented ID */</span></div><div class="line">        <a class="code" href="group__group__canfd__functions.html#ga077680b35c13481998c73e426129a91f">Cy_CANFD_UpdateAndTransmitMsgBuffer</a>(CANFD0, 0UL, &amp;txBuffer, 0u, &amp;context);</div><div class="line">    }</div><div class="line">    <span class="comment">/* These parameters are not used in this snippet */</span></div><div class="line">    (void)bRxFifoMsg;</div><div class="line">    (void)u8MsgBufOrRxFifoNum;</div><div class="line">}</div></div><!-- fragment --><p>CAN FD IP block requires the configuration of a peripheral clock divider. The following code configures an 8-bit clock divider. The default peripheral clock frequency is 72 MHz. The desired divider value minus one must be passed. </p><div class="fragment"><div class="line">    <span class="comment">/* Setup CAN clock (cclk).</span></div><div class="line"><span class="comment">     * This clock is used as base clock of the CAN communication.</span></div><div class="line"><span class="comment">     * Use divider 3 for 24MHz</span></div><div class="line"><span class="comment">     * Use divider 9 for  8MHz</span></div><div class="line"><span class="comment">     */</span></div><div class="line"><span class="preprocessor">    #define DIVIDER_INDEX 0u</span></div><div class="line"><span class="preprocessor">    #define DIVIDER_VALUE (9u - 1u) </span><span class="comment">/* One less than divider value must be used */</span><span class="preprocessor"></span></div><div class="line">    </div><div class="line">    <a class="code" href="group__group__sysclk__clk__peripheral__funcs.html#ga2f480c53ecec720ceed823b2692f1698">Cy_SysClk_PeriphAssignDivider</a>(PCLK_CANFD0_CLOCK_CAN0, <a class="code" href="group__group__sysclk__clk__peripheral__enums.html#gga06138349be16d91fd5d00ded2f4592b8ad2299deae6e36a070de5a60368b319ad">CY_SYSCLK_DIV_8_BIT</a>, DIVIDER_INDEX);</div><div class="line"></div><div class="line">    <a class="code" href="group__group__sysclk__clk__peripheral__funcs.html#gae7042898b1b6835673182e462be6976e">Cy_SysClk_PeriphSetDivider</a>(<a class="code" href="group__group__sysclk__clk__peripheral__enums.html#gga06138349be16d91fd5d00ded2f4592b8ad2299deae6e36a070de5a60368b319ad">CY_SYSCLK_DIV_8_BIT</a>, DIVIDER_INDEX, DIVIDER_VALUE);</div><div class="line"></div><div class="line">    <a class="code" href="group__group__sysclk__clk__peripheral__funcs.html#ga0725e2b222edc601b7d3f56d86d4ff75">Cy_SysClk_PeriphEnableDivider</a>(<a class="code" href="group__group__sysclk__clk__peripheral__enums.html#gga06138349be16d91fd5d00ded2f4592b8ad2299deae6e36a070de5a60368b319ad">CY_SYSCLK_DIV_8_BIT</a>, DIVIDER_INDEX);</div></div><!-- fragment --><p>The CAN FD block uses the Port 5 pins for receive (P5[0]) and transmit (P5[1]).</p><ul>
<li>Connect the specified High-Speed Input Output Multiplexer (HSIOM) selection to the pin.</li>
<li>Set the pins drive mode for RX and TX.</li>
</ul>
<div class="fragment"><div class="line">    <span class="comment">/* Assign pins for CAN FD RX and TX: P5[0] and P5[1]. */</span></div><div class="line"><span class="preprocessor">    #define CANFD_PORT      (P5_0_PORT)</span></div><div class="line"><span class="preprocessor">    #define CANFD_RX_NUM    (P5_0_NUM)</span></div><div class="line"><span class="preprocessor">    #define CANFD_TX_NUM    (P5_1_NUM)</span></div><div class="line"></div><div class="line">    <a class="code" href="group__group__gpio__functions__init.html#ga83a06264feed0e1042671a74339ea155">Cy_GPIO_SetHSIOM</a>(CANFD_PORT, CANFD_RX_NUM, P5_0_CANFD0_TTCAN_RX0);</div><div class="line">    <a class="code" href="group__group__gpio__functions__init.html#ga83a06264feed0e1042671a74339ea155">Cy_GPIO_SetHSIOM</a>(CANFD_PORT, CANFD_TX_NUM, P5_1_CANFD0_TTCAN_TX0);</div><div class="line"></div><div class="line">    <a class="code" href="group__group__gpio__functions__gpio.html#ga97e64dc8c45e7cd73e3012100d03b1fd">Cy_GPIO_SetDrivemode</a>(CANFD_PORT, CANFD_RX_NUM, <a class="code" href="group__group__gpio__drive_modes.html#gaf2fe5dc00ba1770b37e620a01169485c">CY_GPIO_DM_HIGHZ</a>);</div><div class="line">    <a class="code" href="group__group__gpio__functions__gpio.html#ga97e64dc8c45e7cd73e3012100d03b1fd">Cy_GPIO_SetDrivemode</a>(CANFD_PORT, CANFD_TX_NUM, <a class="code" href="group__group__gpio__drive_modes.html#ga9e554ee7c43ac65a6d48274455b53823">CY_GPIO_DM_STRONG</a>);</div></div><!-- fragment --><p> For the CANFD interrupt service routine, the <a class="el" href="group__group__canfd__functions.html#ga89c366a3feb3ef1cd0a3b9779fff718e" title="CAN FD (Status/Error/Rx/Tx) interrupt ISR. ">Cy_CANFD_IrqHandler()</a> can be used. It handles reading data from dedicated RX buffers and RX FIFO buffers. Corresponding callback functions are called for error interrupts, RX interrupts and TX complete interrupt. </p><dl class="section note"><dt>Note</dt><dd>Only RX interrupt sources are enabled by default. Use <a class="el" href="group__group__canfd__functions.html#ga054d85e42f3f2440743c981dbc52ed0a" title="Configures which bits of the interrupt request register can trigger an interrupt event. ">Cy_CANFD_SetInterruptMask()</a> to enable other interrupt sources. </dd>
<dd>
Interrupt flags are set regardless of the interrupt enable register. Cy_CANFD_IrqHandler will check and process all supported interrupts when triggered with any enabled interrupt source.</dd></dl>
<div class="fragment"><div class="line"><span class="comment">/* CANFD interrupt handler */</span></div><div class="line"><span class="keywordtype">void</span> CanfdInterruptHandler(<span class="keywordtype">void</span>)</div><div class="line">{</div><div class="line">    <span class="comment">/* Just call the IRQ handler with the current channel number and context */</span></div><div class="line">    <a class="code" href="group__group__canfd__functions.html#ga89c366a3feb3ef1cd0a3b9779fff718e">Cy_CANFD_IrqHandler</a>(CANFD0, 0, &amp;context);</div><div class="line">}</div></div><!-- fragment --><p> Setup the interrupt handler to be called with the CAN FD events. The CAN FD block has two interrupt lines, which can be assigned to different interrupt sources using <a class="el" href="group__group__canfd__functions.html#ga4f70384d4189cb8a2c95558844b3ad32" title="Configures the bits of the Interrupt Line Select Register to assign the interrupt signal to the line ...">Cy_CANFD_SetInterruptLine()</a>: canfd_0_interrupts0_0_IRQn and canfd_0_interrupts1_0_IRQn. Also, the CAN FD block has a consolidated interrupt canfd_0_interrupt0_IRQn. The following code shows how to set up the interrupt handler. </p><div class="fragment"><div class="line">    <span class="comment">/* Setup the CANFD interrupt */</span></div><div class="line">    {</div><div class="line">        <span class="comment">/* Populate the configuration structure */</span></div><div class="line">        <span class="keyword">const</span> <a class="code" href="structcy__stc__sysint__t.html">cy_stc_sysint_t</a> irq_cfg =</div><div class="line">        {</div><div class="line">            <span class="comment">/* .intrSrc */</span> canfd_0_interrupts0_0_IRQn, <span class="comment">/* CAN FD interrupt number */</span></div><div class="line">            <span class="comment">/* .intrPriority */</span> 3UL</div><div class="line">        };</div><div class="line"></div><div class="line">        <span class="comment">/* Hook the interrupt service routine and enable the interrupt */</span></div><div class="line">        (void) <a class="code" href="group__group__sysint__functions.html#gab2ff6820a898e9af3f780000054eea5d">Cy_SysInt_Init</a>(&amp;irq_cfg, &amp;CanfdInterruptHandler);</div><div class="line">        NVIC_EnableIRQ(canfd_0_interrupts0_0_IRQn);</div><div class="line">    }</div></div><!-- fragment --><p> CAN FD has two bit rate settings, for arbitration and data phases. Both are configured with the same structure, containing a pre-scaler, time segment 1, time segment 2 and synchronization jump width. </p><dl class="section note"><dt>Note</dt><dd>The actual interpretation by the hardware of configured values is one more value than programmed. </dd>
<dd>
The bit rate configured for the CAN FD data phase must be higher or equal to the bit rate configured for the arbitration phase.</dd></dl>
<p>The CAN time quantum (tq) may be programmed in the range of 1 to 32 CAN FD clock periods: tq = (prescaler + 1) mtq, where mtq is CAN FD block's clock period. The length of the bit time is (programmed values) [timeSegment1 + timeSegment2 + 3] tq. <br />
The example below shows the configuration with the 100 kbps arbitration bit rate and 200 kbps data bit rate. This assumes the peripheral clock frequency of 72 MHz divided by 9 to obtain the 8 MHz clock for the CAN FD block. </p><div class="fragment"><div class="line"></div><div class="line">    <a class="code" href="structcy__stc__canfd__bitrate__t.html">cy_stc_canfd_bitrate_t</a> bitrateConfig =</div><div class="line">    {</div><div class="line">        <span class="comment">/* .prescaler     */</span> 10u - 1u,  <span class="comment">/* 0 to 511 */</span></div><div class="line">        <span class="comment">/* .timeSegment1  */</span> 5u - 1u,   <span class="comment">/* 0 to 255 */</span></div><div class="line">        <span class="comment">/* .timeSegment2  */</span> 2u - 1u,   <span class="comment">/* 0 to 127 */</span></div><div class="line">        <span class="comment">/* .syncJumpWidth */</span> 2u - 1u    <span class="comment">/* 0 to 127 */</span></div><div class="line">    };</div><div class="line"></div><div class="line">    <a class="code" href="structcy__stc__canfd__bitrate__t.html">cy_stc_canfd_bitrate_t</a> fastBitrateConfig =</div><div class="line">    {</div><div class="line">        <span class="comment">/* .prescaler     */</span> 5u - 1u,   <span class="comment">/* 0 to 511 */</span></div><div class="line">        <span class="comment">/* .timeSegment1  */</span> 5u - 1u,   <span class="comment">/* 0 to 255 */</span></div><div class="line">        <span class="comment">/* .timeSegment2  */</span> 2u - 1u,   <span class="comment">/* 0 to 127 */</span></div><div class="line">        <span class="comment">/* .syncJumpWidth */</span> 2u - 1u    <span class="comment">/* 0 to 127 */</span></div><div class="line">    };</div><div class="line"></div><div class="line">    <a class="code" href="structcy__stc__canfd__transceiver__delay__compensation__t.html">cy_stc_canfd_transceiver_delay_compensation_t</a> tdcConfig =</div><div class="line">    {</div><div class="line">        <span class="comment">/* .tdcEnabled      */</span> <span class="keyword">false</span>,</div><div class="line">        <span class="comment">/* .tdcOffset       */</span> 0,</div><div class="line">        <span class="comment">/* .tdcFilterWindow */</span> 0</div><div class="line">    };</div></div><!-- fragment --><p>CAN FD driver provides API to setup Message ID filtering. There are standard ID and extended ID filters. The desired count of the filters of each type is specified in the <a class="el" href="structcy__stc__canfd__config__t.html">cy_stc_canfd_config_t</a> structure and is set once during block initialization. It is possible to change the configured filters settings with <a class="el" href="group__group__canfd__functions.html#ga2a1f87235b315ccd380fca0543abaec3" title="Updates the Standard Message ID Filter Element configuration in Message RAM. ">Cy_CANFD_SidFilterSetup()</a> and <a class="el" href="group__group__canfd__functions.html#ga268474c1b1bbc0a0d80ef8ee9041f9c4" title="Updates the Extended Message ID Filter Element configuration in Message RAM. ">Cy_CANFD_XidFilterSetup()</a>. Use the <a class="el" href="structcy__stc__id__filter__t.html" title="Message ID filter register. ">cy_stc_id_filter_t</a> structure to set up one standard ID filter: </p><div class="fragment"><div class="line"><span class="preprocessor">    #define MESSAGE_ID0          (0x00000001UL)</span></div><div class="line"><span class="preprocessor">    #define MESSAGE_ID1          (0x00000010UL)</span></div><div class="line"><span class="preprocessor">    #define MESSAGE_ID2          (0x00000020UL)</span></div><div class="line"><span class="preprocessor">    #define MESSAGE_ID3          (0x00010010UL)</span></div><div class="line"><span class="preprocessor">    #define RX_BUFFER_ELEMENT_1  (0x0UL)</span></div><div class="line"><span class="preprocessor">    #define RX_BUFFER_ELEMENT_2  (0x1UL)</span></div><div class="line"><span class="preprocessor">    #define RX_BUFFER_ELEMENT_3  (0x2UL)</span></div><div class="line"><span class="preprocessor">    #define RX_BUFFER_ELEMENT_4  (0x3UL)</span></div><div class="line">    </div><div class="line">    <span class="keyword">static</span> <span class="keyword">const</span> <a class="code" href="structcy__stc__id__filter__t.html">cy_stc_id_filter_t</a> stdIdFilters[] =</div><div class="line">    {</div><div class="line">        <span class="comment">/* stdIdFilter[0] */</span></div><div class="line">        {</div><div class="line">            <span class="comment">/* .sfid2 */</span> RX_BUFFER_ELEMENT_1,</div><div class="line">            <span class="comment">/* .sfid1 */</span> MESSAGE_ID0,</div><div class="line">            <span class="comment">/* .sfec  */</span> <a class="code" href="group__group__canfd__enums.html#ggae5fe195a7883e282b211bc54e10977f0a37e10c3b20326fbfd1dcd08b2616c582">CY_CANFD_SFEC_STORE_RX_BUFFER</a>,</div><div class="line">            <span class="comment">/* .sft   */</span> <a class="code" href="group__group__canfd__enums.html#gga21b68fc58e117edbae073d981342566aab201278070016e4b6b9f8a063d6273ee">CY_CANFD_SFT_CLASSIC_FILTER</a></div><div class="line">        },</div><div class="line"></div><div class="line">        <span class="comment">/* stdIdFilter[1] */</span></div><div class="line">        {</div><div class="line">            <span class="comment">/* .sfid2 */</span> RX_BUFFER_ELEMENT_2,</div><div class="line">            <span class="comment">/* .sfid1 */</span> MESSAGE_ID1,</div><div class="line">            <span class="comment">/* .sfec  */</span> <a class="code" href="group__group__canfd__enums.html#ggae5fe195a7883e282b211bc54e10977f0a37e10c3b20326fbfd1dcd08b2616c582">CY_CANFD_SFEC_STORE_RX_BUFFER</a>,</div><div class="line">            <span class="comment">/* .sft   */</span> CY_CANFD_SFT_CLASSIC_FILTER</div><div class="line">        }</div><div class="line">    };</div><div class="line">    </div><div class="line">    <a class="code" href="structcy__stc__canfd__sid__filter__config__t.html">cy_stc_canfd_sid_filter_config_t</a> sidFiltersConfig =</div><div class="line">    {</div><div class="line">        <span class="comment">/* .numberOfSIDFilters */</span> <span class="keyword">sizeof</span>(stdIdFilters) / <span class="keyword">sizeof</span>(stdIdFilters[0]),</div><div class="line">        <span class="comment">/* .sidFilter          */</span> stdIdFilters,</div><div class="line">    };</div></div><!-- fragment --><p>Use the <a class="el" href="structcy__stc__extid__filter__t.html" title="Extended message ID filter register. ">cy_stc_extid_filter_t</a> structure to set up an extended ID filter: </p><div class="fragment"><div class="line">    <a class="code" href="structcy__stc__canfd__f0__t.html">cy_stc_canfd_f0_t</a> filter0F0Config =</div><div class="line">    {</div><div class="line">        <span class="comment">/* .efid1 */</span> MESSAGE_ID2,</div><div class="line">        <span class="comment">/* .efec  */</span> <a class="code" href="group__group__canfd__enums.html#gga54cac9dc6e3b4b0ad9f833420dcd0d85a246b8ada4e053806603a033b7f0fb011">CY_CANFD_EFEC_STORE_RX_BUFFER</a></div><div class="line">    };</div><div class="line"></div><div class="line">    <a class="code" href="structcy__stc__canfd__f1__t.html">cy_stc_canfd_f1_t</a> filter0F1Config =</div><div class="line">    {</div><div class="line">        <span class="comment">/* .efid2 */</span> RX_BUFFER_ELEMENT_3,</div><div class="line">        <span class="comment">/* .eft   */</span> <a class="code" href="group__group__canfd__enums.html#gga572525e185ea030f605f74679256f342a4f439933bd71059964565d23557bf7ca">CY_CANFD_EFT_CLASSIC_FILTER</a></div><div class="line">    };</div><div class="line"></div><div class="line">    <a class="code" href="structcy__stc__canfd__f0__t.html">cy_stc_canfd_f0_t</a> filter1F0Config =</div><div class="line">    {</div><div class="line">        <span class="comment">/* .efid1 */</span> MESSAGE_ID3,</div><div class="line">        <span class="comment">/* .efec  */</span> <a class="code" href="group__group__canfd__enums.html#gga54cac9dc6e3b4b0ad9f833420dcd0d85a7343ba05b3674cd56229d842787e9830">CY_CANFD_EFEC_DISABLE</a></div><div class="line">    };</div><div class="line"></div><div class="line">    <a class="code" href="structcy__stc__canfd__f1__t.html">cy_stc_canfd_f1_t</a> filter1F1Config =</div><div class="line">    {</div><div class="line">        <span class="comment">/* .efid2 */</span> RX_BUFFER_ELEMENT_4,</div><div class="line">        <span class="comment">/* .eft   */</span> CY_CANFD_EFT_CLASSIC_FILTER</div><div class="line">    };</div><div class="line"></div><div class="line">    <span class="keyword">const</span> <a class="code" href="structcy__stc__extid__filter__t.html">cy_stc_extid_filter_t</a> extIdFilters[] =</div><div class="line">    {</div><div class="line">        <span class="comment">/* extIdFilter[0] */</span></div><div class="line">        {</div><div class="line">            <span class="comment">/* .f0_f */</span> &amp;filter0F0Config,</div><div class="line">            <span class="comment">/* .f1_f */</span> &amp;filter0F1Config</div><div class="line">        },</div><div class="line"></div><div class="line">        <span class="comment">/* extIdFilter[1] */</span></div><div class="line">        {</div><div class="line">            <span class="comment">/* .f0_f */</span> &amp;filter1F0Config,</div><div class="line">            <span class="comment">/* .f1_f */</span> &amp;filter1F1Config</div><div class="line">        }</div><div class="line">    };</div><div class="line"></div><div class="line">    <a class="code" href="structcy__stc__canfd__extid__filter__config__t.html">cy_stc_canfd_extid_filter_config_t</a> extidFiltersConfig =</div><div class="line">    {</div><div class="line">        <span class="comment">/* numberOfEXTIDFilters */</span> <span class="keyword">sizeof</span>(extIdFilters) / <span class="keyword">sizeof</span>(extIdFilters[0]),</div><div class="line">        <span class="comment">/* extidFilter          */</span> extIdFilters,</div><div class="line">        <span class="comment">/* extIDANDMask         */</span> 0x1fffffffUL</div><div class="line">    };</div></div><!-- fragment --><p>Message IDs that do not match any filter are received according to the global filter set up. The global filter can be set up to receive messages with standard and extended IDs to different FIFO buffers. It can be configured to reject remote frames, as shown below. </p><div class="fragment"><div class="line">    <a class="code" href="structcy__stc__canfd__global__filter__config__t.html">cy_stc_canfd_global_filter_config_t</a> globalFilterConfig =</div><div class="line">    {</div><div class="line">        <span class="comment">/* .nonMatchingFramesStandard  */</span> <a class="code" href="group__group__canfd__enums.html#gga5ce2c01ca9806831dc539727d173e59ca9f84f229041f327f023e9cb8e38b3398">CY_CANFD_ACCEPT_IN_RXFIFO_0</a>,</div><div class="line">        <span class="comment">/* .nonMatchingFramesExtended  */</span> <a class="code" href="group__group__canfd__enums.html#gga5ce2c01ca9806831dc539727d173e59caa461ec9511646d934effbd9c71bd97f1">CY_CANFD_ACCEPT_IN_RXFIFO_1</a>,</div><div class="line">        <span class="comment">/* .rejectRemoteFramesStandard */</span> <span class="keyword">true</span>,</div><div class="line">        <span class="comment">/* .rejectRemoteFramesExtended */</span> <span class="keyword">true</span></div><div class="line">    };</div></div><!-- fragment --><p>The RX FIFO buffers, FIFO 0 and FIFO 1 are configured once on block initialization using <a class="el" href="structcy__en__canfd__fifo__config__t.html" title="Rx FIFO configuration. ">cy_en_canfd_fifo_config_t</a> structure. </p><div class="fragment"><div class="line">    <a class="code" href="structcy__en__canfd__fifo__config__t.html">cy_en_canfd_fifo_config_t</a> rxFifo0Config =</div><div class="line">    {</div><div class="line">        <span class="comment">/* mode                   */</span> <a class="code" href="group__group__canfd__enums.html#gga0017b4985b8b86ca85b9dca5d532803eacf888e2a229311116de20012e4fc7b05">CY_CANFD_FIFO_MODE_BLOCKING</a>,</div><div class="line">        <span class="comment">/* watermark              */</span> 0u,</div><div class="line">        <span class="comment">/* numberOfFifoElements   */</span> 1u,</div><div class="line">        <span class="comment">/* topPointerLogicEnabled */</span> <span class="keyword">false</span></div><div class="line">    };</div><div class="line"></div><div class="line">    <a class="code" href="structcy__en__canfd__fifo__config__t.html">cy_en_canfd_fifo_config_t</a> rxFifo1Config =</div><div class="line">    {</div><div class="line">        <span class="comment">/* mode                   */</span> <a class="code" href="group__group__canfd__enums.html#gga0017b4985b8b86ca85b9dca5d532803eacf888e2a229311116de20012e4fc7b05">CY_CANFD_FIFO_MODE_BLOCKING</a>,</div><div class="line">        <span class="comment">/* watermark              */</span> 0u,</div><div class="line">        <span class="comment">/* numberOfFifoElements   */</span> 1u,</div><div class="line">        <span class="comment">/* topPointerLogicEnabled */</span> <span class="keyword">false</span></div><div class="line">    };</div></div><!-- fragment --><p>The <a class="el" href="structcy__stc__canfd__config__t.html" title="CAN FD configuration. ">cy_stc_canfd_config_t</a> structure is used to pass all configuration to <a class="el" href="group__group__canfd__functions.html#ga8a1f6cffafdd899861203d50d24e7b3e" title="Initializes the CAN FD module. ">Cy_CANFD_Init()</a> function. It is populated with pointers to other structures required and constants, defined before. </p><div class="fragment"><div class="line">    <span class="keyword">const</span> <a class="code" href="structcy__stc__canfd__config__t.html">cy_stc_canfd_config_t</a> config =</div><div class="line">    {</div><div class="line">        <span class="comment">/* .txCallback            */</span> NULL,</div><div class="line">        <span class="comment">/* .rxCallback            */</span> CAN_RxMsgCallback,</div><div class="line">        <span class="comment">/* .errorCallback         */</span> NULL,</div><div class="line">        <span class="comment">/* .canFDMode             */</span> <span class="keyword">true</span>,</div><div class="line">        <span class="comment">/* .bitrate               */</span> &amp;bitrateConfig,</div><div class="line">        <span class="comment">/* .fastBitrate           */</span> &amp;fastBitrateConfig,</div><div class="line">        <span class="comment">/* .tdcConfig             */</span> &amp;tdcConfig,</div><div class="line">        <span class="comment">/* .sidFilterConfig       */</span> &amp;sidFiltersConfig,</div><div class="line">        <span class="comment">/* .extidFilterConfig     */</span> &amp;extidFiltersConfig,</div><div class="line">        <span class="comment">/* .globalFilterConfig    */</span> &amp;globalFilterConfig,</div><div class="line">        <span class="comment">/* .rxBufferDataSize      */</span> <a class="code" href="group__group__canfd__enums.html#gga597fe2f69a8484277fd481ac5384ca7ca2a6fe8e5944a3c017b15cce584d421ee">CY_CANFD_BUFFER_DATA_SIZE_64</a>,</div><div class="line">        <span class="comment">/* .rxFIFO1DataSize       */</span> <a class="code" href="group__group__canfd__enums.html#gga597fe2f69a8484277fd481ac5384ca7ca2a6fe8e5944a3c017b15cce584d421ee">CY_CANFD_BUFFER_DATA_SIZE_64</a>,</div><div class="line">        <span class="comment">/* .rxFIFO0DataSize       */</span> <a class="code" href="group__group__canfd__enums.html#gga597fe2f69a8484277fd481ac5384ca7ca2a6fe8e5944a3c017b15cce584d421ee">CY_CANFD_BUFFER_DATA_SIZE_64</a>,</div><div class="line">        <span class="comment">/* .txBufferDataSize      */</span> <a class="code" href="group__group__canfd__enums.html#gga597fe2f69a8484277fd481ac5384ca7ca2a6fe8e5944a3c017b15cce584d421ee">CY_CANFD_BUFFER_DATA_SIZE_64</a>,</div><div class="line">        <span class="comment">/* .rxFIFO0Config         */</span> &amp;rxFifo0Config,</div><div class="line">        <span class="comment">/* .rxFIFO1Config         */</span> &amp;rxFifo1Config,</div><div class="line">        <span class="comment">/* .noOfRxBuffers         */</span> 0x4u,</div><div class="line">        <span class="comment">/* .noOfTxBuffers         */</span> 0x2u,</div><div class="line">        <span class="comment">/* .messageRAMaddress     */</span> CY_CAN0MRAM_BASE,</div><div class="line">        <span class="comment">/* .messageRAMsize        */</span> 4096u</div><div class="line">    };</div></div><!-- fragment --><p>The <a class="el" href="group__group__canfd__functions.html#ga8a1f6cffafdd899861203d50d24e7b3e" title="Initializes the CAN FD module. ">Cy_CANFD_Init()</a> function initializes the CAN FD block by writing CAN FD configuration registers. <a class="el" href="group__group__canfd__functions.html#ga8a1f6cffafdd899861203d50d24e7b3e" title="Initializes the CAN FD module. ">Cy_CANFD_Init()</a> enables the RX interrupts for new message reception into the dedicated RX buffers, FIFO 0 and FIFO 1. The code example also shows the test mode configuration which can be used to enable the Loopback mode. See <a class="el" href="group__group__canfd__enums.html#gac301ff6eab794c7f718822ef7c289483">cy_stc_canfd_test_mode_t</a> for details. <a class="el" href="group__group__canfd__functions.html#ga8a1f6cffafdd899861203d50d24e7b3e" title="Initializes the CAN FD module. ">Cy_CANFD_Init()</a> sets test mode configuration to CY_CANFD_TEST_MODE_DISABLE. Remember to disable the echo functionality in the RX callback when using a loopback. </p><div class="fragment"><div class="line">    <span class="keywordflow">if</span>(<a class="code" href="group__group__canfd__enums.html#gga8e8bd7856fdc3566bbe2d0c43270c187a0835f4671848804d56b8d29607a5c3a4">CY_CANFD_SUCCESS</a> != <a class="code" href="group__group__canfd__functions.html#ga8a1f6cffafdd899861203d50d24e7b3e">Cy_CANFD_Init</a> (CANFD0, 0, &amp;config, &amp;context))</div><div class="line">    {</div><div class="line">        <span class="comment">/* Error processing */</span></div><div class="line">    }</div><div class="line">    <span class="comment">/* Enables the configuration changes to set Test mode */</span></div><div class="line">    <a class="code" href="group__group__canfd__functions.html#gae0e9450addab2f45af99473022f32f59">Cy_CANFD_ConfigChangesEnable</a>(CANFD0, 0);</div><div class="line">    <span class="comment">/* Sets the Test mode configuration */</span></div><div class="line">    <a class="code" href="group__group__canfd__functions.html#ga6e4fed4a894d0b61c38714569cc94f5c">Cy_CANFD_TestModeConfig</a>(CANFD0, 0, <a class="code" href="group__group__canfd__enums.html#ggac301ff6eab794c7f718822ef7c289483aed426a65133a036a1cb85d131fbe5b56">CY_CANFD_TEST_MODE_DISABLE</a>);</div><div class="line">    <span class="comment">/* Disables the configuration changes */</span></div><div class="line">    <a class="code" href="group__group__canfd__functions.html#ga1960f8d0f6ce39fc1ee0c51b02933fe4">Cy_CANFD_ConfigChangesDisable</a>(CANFD0, 0);</div></div><!-- fragment --><p>To send a CAN FD message, a TX buffer structure must be prepared which consists of the T0 and T1 registers and data array. </p><div class="fragment"><div class="line">    <span class="comment">/* Prepares a CANFD message to transmit */</span></div><div class="line">    uint32_t data[<a class="code" href="group__group__canfd__macros.html#ga2ffb38faee5adf33871a30ad579404dc">CY_CANFD_MESSAGE_DATA_BUFFER_SIZE</a>];</div><div class="line">    <span class="comment">/* Sets up the CANFD TX Buffer */</span></div><div class="line">    <a class="code" href="structcy__stc__canfd__t0__t.html">cy_stc_canfd_t0_t</a> t0registerMsg0 =</div><div class="line">    {</div><div class="line">        <span class="comment">/* id   */</span>  0x200,</div><div class="line">        <span class="comment">/* rtr   */</span> <a class="code" href="group__group__canfd__enums.html#gga9dc2150b5a115fd87cd60f538f7281ceac797e947012ac4b5d191f67b5095682c">CY_CANFD_RTR_DATA_FRAME</a>,</div><div class="line">        <span class="comment">/* xtd   */</span> (<span class="keyword">false</span>) ? <a class="code" href="group__group__canfd__enums.html#gga511e4ae64e16189bfe2e5828ae2d9f25adcba34faabea8d9f6866b65a6a3ffc9c">CY_CANFD_XTD_EXTENDED_ID</a> : <a class="code" href="group__group__canfd__enums.html#gga511e4ae64e16189bfe2e5828ae2d9f25aba189a4f427a087b73a3fd75a80f19ee">CY_CANFD_XTD_STANDARD_ID</a>,</div><div class="line">        <span class="comment">/* esi */</span> <a class="code" href="group__group__canfd__enums.html#gga24bb5c7075c10594b4e276520f64f779a46390b4ec4de5f7c1819fe9f1a0ebbec">CY_CANFD_ESI_ERROR_ACTIVE</a></div><div class="line">    };</div><div class="line"></div><div class="line">    <a class="code" href="structcy__stc__canfd__t1__t.html">cy_stc_canfd_t1_t</a> t1registerMsg0 =</div><div class="line">    {</div><div class="line">        <span class="comment">/* dlc   */</span> 15U,</div><div class="line">        <span class="comment">/* brs   */</span> <span class="keyword">true</span>,</div><div class="line">        <span class="comment">/* fdf   */</span> (<span class="keyword">true</span>) ? <a class="code" href="group__group__canfd__enums.html#gga9a9a243726110708a6e61d77b7a86d1ea0053337533518903d9fa1ec0729a22d2">CY_CANFD_FDF_CAN_FD_FRAME</a> : <a class="code" href="group__group__canfd__enums.html#gga9a9a243726110708a6e61d77b7a86d1ea16e079ea2b407c5c68f8dfd9f3075553">CY_CANFD_FDF_STANDARD_FRAME</a>,</div><div class="line">        <span class="comment">/* efc   */</span> <span class="keyword">false</span>,</div><div class="line">        <span class="comment">/* mm    */</span> 0UL</div><div class="line">    };</div><div class="line"></div><div class="line">    <a class="code" href="structcy__stc__canfd__tx__buffer__t.html">cy_stc_canfd_tx_buffer_t</a> txBuffer =</div><div class="line">    {</div><div class="line">        <span class="comment">/* t0_f        */</span> &amp;t0registerMsg0,</div><div class="line">        <span class="comment">/* t1_f        */</span> &amp;t1registerMsg0,</div><div class="line">        <span class="comment">/* data_area_f */</span> data</div><div class="line">    };</div><div class="line">    </div><div class="line">    <span class="comment">/* Prepare data to send */</span></div><div class="line">    data[0]  = 0x78563412UL;</div><div class="line">    data[1]  = 0x11111111UL;</div><div class="line">    data[2]  = 0x22222222UL;</div><div class="line">    data[3]  = 0x33332222UL;</div><div class="line">    data[4]  = 0x55554444UL;</div><div class="line">    data[5]  = 0x77776666UL;</div><div class="line">    data[6]  = 0x99998888UL;</div><div class="line">    data[7]  = 0xBBBBAAAAUL;</div><div class="line">    data[8]  = 0xDDDDCCCCUL;</div><div class="line">    data[9]  = 0xFFFFEEEEUL;</div><div class="line">    data[10] = 0x78563412UL;</div><div class="line">    data[11] = 0x00000000UL;</div><div class="line">    data[12] = 0x11111111UL;</div><div class="line">    data[13] = 0x22222222UL;</div><div class="line">    data[14] = 0x33333333UL;</div><div class="line">    data[15] = 0x44444444UL;</div><div class="line"></div></div><!-- fragment --><p>To transmit CAN FD messages, the function <a class="el" href="group__group__canfd__functions.html#ga077680b35c13481998c73e426129a91f">Cy_CANFD_UpdateAndTransmitMsgBuffer()</a> is used. The buffer status can be retrieved by <a class="el" href="group__group__canfd__functions.html#ga5c297d07dfd4185ae5d83559a3d4649e" title="Gets the status of the CAN FD Tx buffer. ">Cy_CANFD_GetTxBufferStatus()</a>. It is possible to set a callback function which will be notified whenever a message transmission has been completed. </p><div class="fragment"><div class="line">    <span class="keywordflow">for</span>(;;)</div><div class="line">    {</div><div class="line">        <span class="comment">/* Sends the prepared data using tx buffer 1 and waits for 1000ms */</span></div><div class="line">        <a class="code" href="group__group__canfd__functions.html#ga077680b35c13481998c73e426129a91f">Cy_CANFD_UpdateAndTransmitMsgBuffer</a>(CANFD0, 0u, &amp;txBuffer, 1u, &amp;context);</div><div class="line">        <a class="code" href="group__group__syslib__functions.html#gaad1c32546fdb0e3c6fa8b46fb95843b5">Cy_SysLib_Delay</a>(1000u);</div><div class="line">    }</div></div><!-- fragment --> <h1><a class="anchor" id="group_canfd_section_more_information"></a>
More Information</h1>
<p>For more information on the CAN FD peripheral, refer to the technical reference manual (TRM).</p>
<h1><a class="anchor" id="group_canfd_changelog"></a>
Changelog</h1>
<table class="doxtable">
<tr>
<th>Version</th><th>Changes</th><th>Reason for Change </th></tr>
<tr>
<td>1.40 </td><td>Updated APIs <a class="el" href="group__group__canfd__functions.html#ga8a1f6cffafdd899861203d50d24e7b3e">Cy_CANFD_Init</a> , <a class="el" href="group__group__canfd__functions.html#gace49624f024ac7f355d4ffcb3c13fd8a">Cy_CANFD_CalcRxBufAdrs</a>, <a class="el" href="group__group__canfd__functions.html#ga1d9cf5eec557299afea5738b9980acec">Cy_CANFD_CalcRxFifoAdrs</a>, <a class="el" href="group__group__canfd__functions.html#ga268474c1b1bbc0a0d80ef8ee9041f9c4">Cy_CANFD_XidFilterSetup</a>.  </td><td>Bug Fixes.  </td></tr>
<tr>
<td>1.30 </td><td>Updated <a class="el" href="group__group__canfd__functions.html#ga8a1f6cffafdd899861203d50d24e7b3e">Cy_CANFD_Init()</a> and <a class="el" href="group__group__canfd__functions.html#ga0849b023b3b145ede68d057561a2aa32">Cy_CANFD_DeInit()</a> functions. Added volatile qualifier to prevent loop optimization. </td><td>Code Enhancement.  </td></tr>
<tr>
<td>1.20 </td><td>Added const modifier to the functions parameters where needed. Improved error handling in <a class="el" href="group__group__canfd__functions.html#ga8a1f6cffafdd899861203d50d24e7b3e">Cy_CANFD_Init()</a> and <a class="el" href="group__group__canfd__functions.html#ga89c366a3feb3ef1cd0a3b9779fff718e">Cy_CANFD_IrqHandler()</a>.  </td><td>Source code cleanup.  </td></tr>
<tr>
<td>1.10 </td><td>Updated <a class="el" href="group__group__canfd__functions.html#ga8a1f6cffafdd899861203d50d24e7b3e">Cy_CANFD_Init()</a> functions. </td><td>Allow initing CANFD with 0 number of SID/XID filters.  </td></tr>
<tr>
<td>1.0.1 </td><td>Updated description of the <a class="el" href="group__group__canfd__functions.html#ga8a1f6cffafdd899861203d50d24e7b3e">Cy_CANFD_Init()</a> and <a class="el" href="group__group__canfd__functions.html#ga0849b023b3b145ede68d057561a2aa32">Cy_CANFD_DeInit()</a> functions. </td><td>Documentation update and clarification.  </td></tr>
<tr>
<td>1.0 </td><td>Initial version </td><td></td></tr>
</table>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="groups"></a>
API Reference</h2></td></tr>
<tr class="memitem:group__group__canfd__macros"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__canfd__macros.html">Macros</a></td></tr>
<tr class="memdesc:group__group__canfd__macros"><td class="mdescLeft">&#160;</td><td class="mdescRight">This section describes the CAN FD Macros. <br /></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:group__group__canfd__functions"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__canfd__functions.html">Functions</a></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:group__group__canfd__data__structures"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__canfd__data__structures.html">Data Structures</a></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:group__group__canfd__enums"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__canfd__enums.html">Enumerated Types</a></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part
<div id="nav-path" class="navpath">
    <ul>
        <li class="footer">
            Generated for <b>MTB CAT1 Peripheral driver library</b> by <b>Cypress Semiconductor Corporation</b>.
            All rights reserved.
        </li>
    </ul>
</div>
-->
</body>
</html>
